/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Yahtzee;

/**
 *
 * @author agreseth fo real
 */
import java.net.*;
import java.io.*;
import javax.swing.*;
public class MultiServer {

    ServerSocket serverSocket = null;
    boolean listening = true;
    int port;
    String receieved;
    ServerGUI gui;
    String[] ipAddress;
    int count;

    public MultiServer(int funport, ServerGUI gu)
    {
        port = funport;
        this.gui = gu;
    }
    public void start()
    {
        try
        {

            serverSocket = new ServerSocket(port);
        }
        catch (IOException e)
        {
            System.err.println("Could not listen on port: " + port);
            System.exit(-1);
        }

        ipAddress = new String[200];
        count = 0;
        while (listening)
        {
            try
            {
                //test
                JOptionPane.showMessageDialog(null, serverSocket.getLocalSocketAddress());
                
                count++;
                new MultiServerThread(serverSocket.accept(),this.gui,this).start();                
                System.out.println("I made it homeie");
            }
            catch (IOException e)
            {
                System.err.println("Problem with the thread...");
            }
        }


    }

    public void setIP(String ip)
    {
        ipAddress[count] = ip;
        for(int i=1; i < count+1; i++)
        {
            System.out.println("hi mom " +ipAddress[i]);
            gui.messagesTextArea.append(ipAddress[i]+"\n");
        }
    }
    
    public String[] getList()
    {
        ipAddress[0] = "/123.456.789.000";
        return ipAddress;
    }
    
    public String receive()
    {
        return receieved;
    }
    public void close()
    {
        try
        {
            serverSocket.close();
        }
        catch (IOException e)
        {
            System.err.println("Problem closing the socket...");
        }
    }



}